package com.wfm.threadlocal;

public class MyThreadLocal {
    ThreadLocal<Integer> local = ThreadLocal.withInitial(()->10);

    public void add(){
        String name = Thread.currentThread().getName();
        System.out.println(name+"local:"+local.get());
        for (int i = 0; i < 10000; i++) {
            local.set(local.get()+1);
        }
        System.out.println(name+"local:"+local.get());
    }

    public void mul(){
        String name = Thread.currentThread().getName();
        System.out.println(name+"local:"+local.get());
        for (int i = 0; i < 10; i++) {
            local.set(local.get()*2);
        }
        System.out.println(name+"local:"+local.get());
    }

    public void addCommon(){
        int common = 10;
        String name = Thread.currentThread().getName();
        System.out.println(name+"common:"+common);
        for (int i = 0; i < 10000; i++) {
            common=common+1;
        }
        System.out.println(name+"common:"+common);
    }
}
